package br.edu.ufcg.dsc.actions.user;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.config.ParentPackage;
import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.domain.Library;
import br.edu.ufcg.dsc.domain.UserType;
import br.edu.ufcg.dsc.services.LibraryService;

import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/user/userDetails.jsp")
@ParentPackage(value = "myPackage")
public class FindUserAction extends BaseUserAction implements Preparable{

	private static final long serialVersionUID = 8161395602084802160L;

	//private Map<UserType, String> types;
	private List<String> librariesNames, types;
	
	public void prepare() throws Exception{
		super.prepare();
		//types = new TreeMap<UserType, String>();
		types = new ArrayList<String>();
		types.add(UserType.ADMIN.name());
		types.add(UserType.LIBRARIAN.name());
		types.add(UserType.STUDENT.name());
		types.add(UserType.TEACHER.name());
		/*types.put(UserType.ADMIN, "Admin");
		types.put(UserType.LIBRARIAN, "Librarian");
		types.put(UserType.STUDENT, "Student");
		types.put(UserType.TEACHER, "Teacher");*/
	}

/*	public Map<UserType, String> getTypes() {
		return types;
	}

	public void setTypes(Map<UserType, String> types) {
		this.types = types;
	}*/
	
	public List<String> getLibraries(String top){
		System.out.println("ENTROU TOP: " + top);
		if (top.equals(UserType.LIBRARIAN.name())){
			librariesNames.clear();
			List<Library> libraries = LibraryService.findAll();
			for(int i = 0; i < libraries.size(); i++)
				librariesNames.add(libraries.get(i).getName());
			return librariesNames;
		}
		return null;
	}

	public List<String> getTypes() {
		return types;
	}

	public void setTypes(List<String> types) {
		this.types = types;
	}
}

